<template>
    <h2>用户注册</h2>
    <table>
        <tr>
            <td>用户名：</td>
            <td>
                <input type="text" v-model="UserName">
            </td>
        </tr>
        <tr>
            <td>用户密码：</td>
            <td>
                <input type="text" v-model="Password">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" value="注册" @click="zhu" />
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const UserName = ref('');
const Password = ref('');
const router = useRouter();
const zhu = () => {
    axios.post("http://localhost:49765/api/Jie/AddLogin", {
        UserName: UserName.value,
        Password: Password.value
    })
        .then(res => {
            if (res.data == -1) {
                alert("用户已存在");
                return;
            }
            else if (res.data > 0) {
                alert("注册成功");
                router.push("/Login");
            }
        })
}
</script>